import SpecAdjoinMatrix from "../../../utils/sku-util/spec-adjoin-martix";
import {
  storeBindingsBehavior
} from "mobx-miniprogram-bindings";
import base from "@src/store/base";
import $math from "@src/common/math"
import router from "@src/router";
import color from "@src/common/color";
Component({
  behaviors: [storeBindingsBehavior],
  storeBindings: [{
    store: base,
    fields: ['isiPhoneX', 'themeColor', 'themeTitleColor']
  }],
  properties: {
    buyingTips: {
      type: Boolean,
      value: false
    },
    bookingStatus: {
      type: Boolean,
      value: false
    },
    //秒杀商品的信息
    // selSkuActive:{
    //   type:Object,
    //   value:{}
    // },
    goodsTypeNew: {
      type: String,
      value: ""
    },
    shopCarInfo: {
      type: Object,
      value: {},
      observer(newVal, oldVal, changedPath) {
        // 重新计算出已经选择的规格id 列表
        if (Object.keys(newVal).length > 0) this.setData({
          formCarInitStatus: true
        })

      }
    },
    goodsBargains: {
      type: Array,
      value: [],
      observer(newVal, oldVal, changedPath) {
        newVal.forEach((item, index) => {
          item.soldOut = false;
          item.collStatus = false;
          //第一种
          if (item.inventory === 0 || item.status === 0) {
            //以及售完
            item.soldOut = true
          } else {
            // item.lastNumber=(item.perLimitNum===0?item.inventory:item.perLimitNum)<=item.inventory?item.perLimitNum:item.inventory
            item.lastNumber = item.perLimitNum === 0 ? item.inventory : (item.perLimitNum <= item.inventory ? item.perLimitNum : item.inventory)
            //第二种
            if (item.lastNumber < item.leastNum) {
              //以及售完
              item.soldOut = true
            } else if (item.leastNum > 0 && item.status !== 0 && item.lastNumber >= item.leastNum) {
              item.collStatus = true
            }
          }
        })
        this.setData({
          collInfo: newVal
        });
        this.changeCollList()
        console.log(this.data.collInfo, "collInfo")
      }
    },
    activityShow: {
      type: Boolean,
      value: false
    },
    dialogShow: {
      type: Boolean,
      value: false
    },
    zIndex: {
      type: Number,
      value: 5000
    },
    deliveryType: {
      type: String,
      value: "",
      observer(newVal, oldVal, changedPath) {}
    },
    goodsObj: {
      type: Object,
      value: {}
    },
    goodsDelivery: {
      type: Object,
      value: [],
      observer: "initDelivery"
    },
    imgList: {
      type: Object,
      value: []
    },
    goodsBuyRule: {
      type: Object,
      value: {}
    },
    skuInfo: {
      type: Object,
      value: {},
      observer(newVal, oldVal, changedPath) {}
    },
    //已选中的sku对象
    selectSkuObj: {
      type: Object,
      observer(newVal, oldVal, changedPath) {}
    },
    //是否隐藏立即购买按钮
    hiddenNowBuy: {
      type: Boolean,
      value: false
    },
    deliveryTypeShow: {
      type: Boolean,
      value: true
    },
    //是否隐藏添加到购物车按钮
    hiddenAddCart: {
      type: Boolean,
      value: false,
    },
    //是否需要影藏后清空内容
    ifHiddenAfterClear: {
      type: Boolean,
      value: false
    },
    //是否开启预售
    presell: {
      type: Boolean,
      value: false
    },
    goodsPresell: {
      type: Object,
      value: {}
    },
    groupShopType: {
      type: String,
      value: "",
    },
    joinGroupOrigin: {
      type: String,
      value: "",
      observer(newVal, oldVal, changedPath) {
        if (newVal === 'collect' || newVal === 'tuxedo') {
          this.setData({
            groupShopStatus: true
          })
        }
        if (newVal === "collect") {
          if (!this.data.goodsObj.deliveryTypes[0] || this.data.aboutGroupInfoItem.deliveryStatus) return
          this.setData({
            deliveryType: this.data.goodsObj.deliveryTypes[0]
          })
          this.triggerEvent('deliveryType', this.data.goodsObj.deliveryTypes[0])
        }
      }
    },
    groupList: {
      type: Array,
      value: [],
      observer(newVal, oldVal, changedPath) {
        if (newVal.length > 0) {
          newVal.forEach((item, index) => {
            // if(item.groupType){
            //   this.setData({groupType:false,groupActivityInfo:item});
            //   this.handleNewOption(this.data.groupActivityInfo)
            //   this.judegGroupListCheck(this.data.specsS)
            // }

            // this.setData({
            //   [`groupList[${index}].disable`]:false,
            // })
          })
        }

      }
    },
    activityInfo: {
      type: Object,
      value: {},
      observer(newVal, oldVal, changedPath) {}
    },
    //拼团单独购买，用于购买时传入判
    oneselfGroup: {
      type: Boolean,
      value: true,
      observer(newVal, oldVal, changedPath) {
        if (newVal === true) {
          this.setData({
            groupType: true
          })
        }
      }
    },
    groupShopStatus: {
      type: Boolean,
      value: false,
      observer(newVal, oldVal, changedPath) {

      }
    },
    //参加拼团活动的活动编号
    groupActivityNo: {
      type: String,
      value: "",
      observer(newVal, oldVal, changedPath) {
        let changeGroupNoStatue;
        this.data.groupList.forEach((item, index) => {
          if (newVal === item.activityNo) {
            item.rule.groupLeaderDiscount = false
            this.setData({
              groupType: false,
              groupActivityInfo: item
            });
            this.triggerEvent("changSelSkuActive", item)
            item.groupType = true
            changeGroupNoStatue = true
          } else {
            item.groupType = false
          }
        })
        if (changeGroupNoStatue) {
          this.handleNewOption(this.data.groupActivityInfo)
          this.judegGroupListCheck(this.data.specsS)
        } else {
          this.setData({
            groupType: true,
            groupActivityInfo: null
          });
          this.setData({
            oneselfGroup: true
          })
        }
        this.setData({
          groupList: this.data.groupList
        })
      }
    },
    aboutGroupInfoItem: {
      type: Object,
      value: null,
      observer(newVal, oldVal, changedPath) {
        if (newVal && newVal.creatorDeliveryType) this.triggerEvent('deliveryType', newVal.creatorDeliveryType)

        // if (this.data.joinGroupOrigin === 'tuxedo' && newVal) {
        //     this.data.groupList.some((v,i)=>{
        //       if(v.activityNo===newVal.groupActivityNo){
        //         debugger
        //         this.setData({activityInfo:v})
        //         this.handleNewOption(v)
        //
        //       }
        //     })
        //
        // }
      },
    },
    joinGroupPageInfo: {
      type: Object,
      value: null
    }
  },

  options: {
    multipleSlots: true,
    addGlobalClass: true
  },
  observers: {
    dialogShow: function (v) {
      // if (this.data.dialogShow&&this.data.selectSkuObj) {
      this.init(this.data.selectSkuObj)
      //给予默认值
      if (this.data.groupActivityInfo && this.data.joinGroupOrigin === 'tuxedo') {
        this.triggerEvent("changSelSkuActive", this.data.groupActivityInfo)
      }
      if (!v) {
        this.setData({
          joinGroupOrigin: ''
        })
      }
      // if(Object.keys(this.data.shopCarInfo)>0){
      //   this.init()
      // }else {
      //   this.init(this.data.selectSkuObj)
      // }
      // }
    },
    'boxArr,count': function (boxArr, count) {
      if (boxArr && this.data.goodsPresell) {
        if (this.data.goodsPresell.type === 'DEPOSIT') {
          let deposit = $math.mul(this.data.goodsPresell.skuDeposit[boxArr.skuId].deposit / 100, this.data.count);
          this.setData({
            deposit
          })
        }
      }
    },
    'groupActivityInfo': function (v) {
      // debugger
      // if(this.data.groupShopStatus){
      //   this.setData({ deliveryType: this.data.aboutGroupInfoItem.creatorDeliveryType })
      //   this.triggerEvent('deliveryType',this.data.aboutGroupInfoItem.creatorDeliveryType )
      //   return
      // }
      if (this.data.aboutGroupInfoItem && v) {
        const deliveryStatus = v.deliveryList.some((v1, i) => {
          if (v1.deliveryType === this.data.aboutGroupInfoItem.creatorDeliveryType) {
            if (v1.leaderCollect) {
              return !!v1.leaderCollectOptional
            } else {
              return true
            }
          }
        })
        this.setData({
          ['aboutGroupInfoItem.deliveryStatus']: deliveryStatus
        })
        console.log(this.data.aboutGroupInfoItem, this.data.deliveryType)
        // debugger
        if (deliveryStatus) {
          this.setData({
            deliveryType: this.data.aboutGroupInfoItem.creatorDeliveryType
          })
          this.triggerEvent('deliveryType', this.data.aboutGroupInfoItem.creatorDeliveryType)
        } else {
          this.setData({
            deliveryType: v.deliveryTypes[0]
          })
          this.triggerEvent('deliveryType', v.deliveryTypes[0])
        }
      }

      if (v && !v.deliveryTypes.includes(this.data.deliveryType)) {
        this.setData({
          deliveryType: v.deliveryTypes[0]
        })
        this.triggerEvent('deliveryType', v.deliveryTypes[0])
      }
    },
    'groupShopStatus': function (v) {
      //当是参团时将参团的类型传入
      if (this.data.groupActivityInfo && !this.data.groupType && v && this.data.joinGroupOrigin !== "collect" && this.data.aboutGroupInfoItem.creatorDeliveryType) {
        this.triggerEvent('deliveryType', this.data.aboutGroupInfoItem.creatorDeliveryType)
      }
    },
    'themeColor': function (themeColor) {
      if (!themeColor) {
        return;
      }
      this.setData({
        'themeColorRgba': color.HexToRGB(themeColor, 16)
      })
    }
  },
  data: {
    //content高度
    contentHeight: 20,
    // 数量
    count: 1,
    boxArr: {
      imgUrl: null
    },
    specList: [],
    specsS: [],
    collInfo: [], //搭配参数
    specAdjoinMatrix: [],
    selectObj: null,
    express: null,
    local: null,
    selfPickup: null,
    deposit: null,
    formCarInitStatus: false,
    groupActivityInfo: null, //当前选择的拼团项
    groupActivityInfoSku: null,
    groupType: true, //单独购买

  },
  pageLifetimes: {
    hide() {
      this.setData({
        groupActivityNo: ""
      })
    },
  },
  methods: {
    // onHide(){
    //   debugger
    //   this.handGroupList()
    //   this.setData({
    //     groupActivityNo:""
    //   })
    // },

    formCarInitSku() {
      let newVal = this.data.shopCarInfo;
      let collList = []
      let collInfo = this.data.collInfo
      if (newVal.children) {
        collInfo.forEach((item1, index1) => {
          newVal.children.forEach((item2, index2) => {
            if (item1.title === item2.title) {
              item1.collStatus = true;
              item1.num = item2.num
              collList.push({
                goodsId: item2.goodsId,
                num: item2.num,
                skuId: item2.skuId,
                type: item2.type
              })
            }
          })
        })
      }


      let specsS = []
      let skuInfo = JSON.parse(newVal.skuInfo); //购物车中已经传来的sku信息
      let specList = JSON.parse(JSON.stringify(this.data.skuInfo.specList)); //全部商品部件信息
      if (skuInfo) {
        specList.forEach((item1, index1) => {
          skuInfo.forEach((skuItem, skuIndex) => {
            item1.attrList.forEach((item2, index2) => {
              if (item2.title === skuItem) {
                specsS.push(item2.id)
                item2.select = !item2.select
              }
            })
          })
        })
      }

      // 重新生成已选择的规格列表
      this.setData({
        specsS: specsS,
        specList: specList,
        formCarInitStatus: false,
        collInfo: collInfo
      });
      // 重置规格状态(已选和禁用)
      this.resetSpecStatus(specsS)
      //我在点击规格的时候就触发传值了
      this.triggerEvent('skuObjFun', this.data.boxArr);

    },
    //去开卡页面
    openCard() {
      let urlParams = [{
        page: 'mine'
      }, {
        data: null
      }];
      urlParams = JSON.stringify(urlParams);
      console.log('urlParams', urlParams)
      let goodsDetail = true;
      router.push({
        name: 'indexChooseCard',
        params: {
          goodsDetail: goodsDetail
        }
      })
    },
    changeCollList() {
      var collList = [];
      this.data.collInfo.forEach((item, index) => {
        if (item.collStatus && item.leastNum <= item.lastNumber) {
          collList.push({
            goodsId: item.goodsId,
            num: item.showNum || item.leastNum || 1,
            skuId: item.skuId,
            type: item.type
          })
        }
      })
      this.triggerEvent('minirorAddcoll', collList)
    },
    init(selectSkuObj) {
      console.log('打开弹框selectSkuObj', selectSkuObj)
      let specList = JSON.parse(JSON.stringify(this.data.skuInfo.specList))
      let specsS = Array(specList.length).fill("");
      if (!selectSkuObj) {
        selectSkuObj = this.initSelectSkuObj();
      }
      if (selectSkuObj && selectSkuObj.specAttrs && selectSkuObj.stockNum) {
        specsS = selectSkuObj.specAttrs.filter((s) => s);
      }
      this.setData({
        specsS: specsS,
        specList: specList
      })
      this.initGroupShow(selectSkuObj.skuId)
      this.initGroupType()
      this.initAdjoinMatrixFunc(this.data.skuInfo.specList, this.data.goodsObj.skuInfo.skuList)
      console.log('selectSkuObj', 'specsS', selectSkuObj, specsS)
      this.resetSpecStatus(specsS);
      this.changeCollList();
    },
    //选择几人团拼团类型
    initGroupType(e) {
      let specsS = []
      let specList = this.data.specList
      specList.forEach(item => {
        item.attrList.forEach(item2 => {
          if (item2.select === true) {
            specsS.push(item2.id)
          }
        })
      })
      let groupList = this.data.groupList;
      //点击单独购买和解决未定义报红
      if (e && e.currentTarget.dataset) {
        if (!e.currentTarget.dataset.item) {
          //单独购买
          groupList.forEach((item, index) => {
            item.groupType = false
          })
          this.setData({
            groupList,
            groupType: true,
            oneselfGroup: true,
            groupActivityInfoSku: null
          })
          this.resetSpecStatus(specsS)
          return;
        } else if (e.currentTarget.dataset.item.disable && specsS.length !== 0) {
          return;
        }
      } else {
        return;
      }
      console.log("改变拼团活动")
      //点击拼团
      console.log(this.data.groupActivityInfo, this.data.aboutGroupInfoItem)
      if (e.currentTarget.dataset.item) {
        this.setData({
          groupActivityInfo: e.currentTarget.dataset.item,
          groupType: false,
          oneselfGroup: false,
          groupShopStatus: e.currentTarget.dataset.isoneselfshop
        });
        if (this.data.aboutGroupInfoItem && this.data.aboutGroupInfoItem.activityNo === e.currentTarget.dataset.item.activityNo && this.data.joinGroupOrigin) {
          this.setData({
            groupShopStatus: true
          })
        }
        this.triggerEvent("changSelSkuActive", e.currentTarget.dataset.item)
        this.handleNewOption(this.data.groupActivityInfo)
        // groupList.forEach((item,index)=>{
        //   if(item.activityNo===this.data.groupActivityInfo.activityNo){
        //     item.groupType=true
        //   }else {
        //     item.groupType=false
        //   }
        // })
        // this.setData({groupList})
        this.resetSpecStatus(specsS)
        this.judegGroupListCheck(specsS);
      }
    },
    //选择sku和初始化时候展示的组团信息
    initGroupShow(skuId) {
      if (this.data.groupList.length === 0) return
      const groupList = this.data.groupList.map((item1, index1) => {
        item1.disable = !item1.skuList.some((item2, index2) => {
          if (item2.skuId == skuId) {
            if (item1.rule.groupLeaderDiscount) {
              item1.groupPrice = item2.price;
            } else {
              item1.groupPrice = item2.price;
            }
            return true
          } else if (index2 === 0) {
            if (item1.rule.groupLeaderDiscount) {
              item1.groupPrice = item2.price;
            } else {
              item1.groupPrice = item2.price;
            }
          }
        })
        console.log(item1.disable)
        return item1
      })
      console.log(groupList)
      this.setData({
        groupList
      })
    },
    initSelectSkuObj() {
      if (!this.data.goodsObj.skuInfo) return
      let skuList = this.data.goodsObj.skuInfo.skuList;
      if (!skuList || skuList.length === 0) {
        return null;
      }
      for (let i = 0; i < skuList.length; i++) {
        let sku = skuList[i]
        if (sku.status === 1 && sku.stockNum > 0) {
          return sku;
        }
      }
      return skuList[0];
    },
    initDelivery(goodsDelivery) {
      let express = null,
        local = null,
        selfPickup = null;
      if (!goodsDelivery || goodsDelivery.length === 0) {
        this.setData({
          express,
          local,
          selfPickup
        });
        return;
      }
      for (let i = 0; i < goodsDelivery.length; i++) {
        if (goodsDelivery[i].deliveryType === 'SELF_PICKUP') {
          selfPickup = goodsDelivery[i];
        } else if (goodsDelivery[i].deliveryType === 'LOCAL') {
          local = goodsDelivery[i];
        } else if (goodsDelivery[i].deliveryType === 'EXPRESS') {
          express = goodsDelivery[i];
        }
      }
      this.setData({
        express,
        local,
        selfPickup
      });
    },

    //初始化矩阵, 用于生成可选的spec, 可以当成黑盒子,
    // 输入已选择的规格id[attrIdA, attrIdB], 返回可选的attrId
    initAdjoinMatrixFunc(specList, skuList) {
      // 输入参数
      let inputSpecList = []
      let inputSkuList = []
      // 规格映射 转换为 {id: x, title: x, list:[atrr.id]}
      specList.forEach(item => {
        let list = [];
        item.attrList.forEach(item2 => {
          list.push(item2.id)
        })
        inputSpecList.push({
          id: item.id,
          list: list
        })
      })
      // 正常状态的sku矩阵
      skuList.forEach((item, i) => {
        if (item.status && item.stockNum >= 1) {
          item.specAttrs = item.specAttrs.filter((s) => s);
          inputSkuList.push(item)
        }
      })
      let specAdjoinMatrix = new SpecAdjoinMatrix(inputSpecList, inputSkuList);
      console.log('specAdjoinMatrix', specAdjoinMatrix)
      this.setData({
        specAdjoinMatrix: specAdjoinMatrix
      })
    },
    //点击规格item
    handleClick(e) {
      // 重新计算出已经选择的规格id 列表
      let specList = this.data.specList;
      let items = e.currentTarget.dataset.item; //当前item
      if (items.disable) {
        return;
      }
      let index = e.currentTarget.dataset.index; //父级index
      let specsS = []
      // 选中状态扭转
      specList[index].attrList.forEach(item2 => {
        if (items.id === item2.id) {
          item2.select = !item2.select
        } else {
          item2.select = false;
        }
      })
      specList.forEach(item => {
        item.attrList.forEach(item2 => {
          if (item2.select === true) {
            specsS.push(item2.id)
          }
        })
      })
      // 重新生成已选择的规格列表
      this.setData({
        specsS: specsS
      })
      // 重置规格状态(已选和禁用)
      this.resetSpecStatus(specsS);
      // 判断当前的sku拼团活动中是否有，没有则设置为false；有的话则true
      this.judegGroupListCheck(specsS);
      //我在点击规格的时候就触发传值了
      console.log(this.data)
      let flag = this.ifSpecListAllChange()
      if (flag) this.triggerEvent('skuObjFun', this.data.boxArr);
      if (this.data.boxArr && this.data.boxArr.skuId && this.data.goodsTypeNew === 'GROUP' && this.data.bookingStatus) this.initGroupShow(this.data.boxArr.skuId)
    },
    // 判断当前的sku拼团活动中是否有，没有则设置为false；有的话则true
    judegGroupListCheck(specsS) {
      const list = this.data.skuInfo.skuList.filter((item, index) => {
        const disableStatus = specsS.every((item1, index1) => {
          if (item.specAttrs.includes(item1)) return true
        })
        if (disableStatus) {
          return item.skuId
        }
      })
      if (!Object.keys(list).length) return
      this.data.groupList.forEach((item, index) => {
        const disable = item.skuList.some((item1, index1) => {
          if (list[0].skuId === item1.skuId && item1.stockNum > 0) {
            if (this.data.groupActivityInfo && this.data.groupActivityInfo.activityNo === item.activityNo) {
              this.setData({
                groupActivityInfoSku: item1
              })
            }
            return true
          }
        });
        this.setData({
          [`groupList[${index}].disable`]: !disable
        })
      })
    },
    resetSpecStatus(specsS) {
      //specsS [35,28,69]这种格式
      let specList = JSON.parse(JSON.stringify(this.data.specList));
      //获得可选项
      // if(!this.data.groupType){
      if (!this.data.groupType) {
        this.initAdjoinMatrixFunc(this.data.skuInfo.specList, this.data.groupActivityInfo.skuList)
      } else {
        this.initAdjoinMatrixFunc(this.data.skuInfo.specList, this.data.goodsObj.skuInfo.skuList)
      }
      let nowOption = this.data.specAdjoinMatrix.getSpecscOptions(specsS);
      //判断不是单独购买重新给予可选项

      console.info("specsS", specsS)
      console.info("nowOption", nowOption)
      if (nowOption.length > 0) {
        specList.forEach(item => {
          item.attrList.forEach(item2 => {
            if (nowOption.includes(item2.id)) {
              item2.disable = false
            } else {
              item2.disable = true
            }
            if (specsS.includes(item2.id)) {
              item2.select = true;
            }
          })
        })
      } else {
        //没有可选规则
        specList.forEach(item => {
          item.attrList.forEach(item2 => {
            item2.disable = true
          })
        })
      }
      this.setData({
        specList: specList
      });
      console.log('specList', specList)
      if (this.data.formCarInitStatus) this.formCarInitSku()
      this.selectObjFnc()
    },
    //查询在拼团活动下 可用的列表
    handleNewOption(activityInfo) {
      activityInfo.skuList.forEach((item1, index1) => {
        // console.log(this.data.selSkuActive,this.data.skuInfo,this.data.selectSkuObj)
        this.data.skuInfo.skuList.forEach((item2, index2) => {
          if (item1.skuId === item2.skuId) {
            let specAttrs = item2.specAttrs.filter((item3, index3) => {
              if (item3 > 0) return item3
            })
            this.setData({
              [`groupActivityInfo.skuList[${index1}].specAttrs`]: specAttrs,
              [`groupActivityInfo.skuList[${index1}].status`]: 1,
            })
          }
        })
      })
    },
    //组装已选对象
    selectObjFnc() {
      let specsS = this.data.specsS;
      let specList = this.data.skuInfo.specList;
      let skuList = this.data.goodsObj.skuInfo.skuList;
      let selectObj = {}
      if (specsS.length === specList.length && (specsS.indexOf("") === -1)) {
        skuList.forEach(item => {
          //如果这两个数组的id完全想等
          item.specAttrs = item.specAttrs.filter((s) => s);
          if (item.specAttrs.sort().toString() === specsS.sort().toString()) {
            selectObj = item
          }
        })
        this.setData({
          boxArr: selectObj
        })
      }

      // console.log(this.data.selSkuActive,this.data.boxArr)
    },

    //监听子组件的count变化
    handleNumChange(e) {
      let num = parseInt(e.detail.val);
      this.setData({
        count: num
      });
    },
    //监听高度
    handleContentHeight(e) {
      this.setData({
        contentHeight: e.detail
      })
    },
    handleViewImg(e) {
      let url = e.currentTarget.dataset.url
      wx.previewImage({
        urls: [getApp().toFullUrl(url)]
      })
    },
    handleDeliveryType(e) {
      let type = e.currentTarget.dataset.type;
      this.setData({
        deliveryType: type
      })
      this.triggerEvent('deliveryType', type)
    },
    //设置spec组件隐藏
    closeDialog() {
      this.setData({
        groupActivityNo: ""
      })
      this.emitSkuChange()
      this.setData({
        dialogShow: false
      })
      if (this.data.ifHiddenAfterClear) {
        let specList = this.data.specList
        this.setData({
          boxArr: {},
          specsS: []
        })
        let specListLength = specList.length;
        for (let i = 0; i < specListLength; i++) {
          for (let j = 0; j < specList[i].attrList.length; j++) {
            specList[i].attrList[j].select = false
          }
        }
        this.setData({
          specList: specList,
        })
      }
    },
    specAddCart() {
      let flag = this.ifSpecListAllChange()
      if (flag) {
        let count = this.data.count;
        let collList = [];

        this.closeDialog();
        this.triggerEvent('minitorAddcart', count)
      } else {
        wx.showToast({
          title: "请将属性选择完整",
          icon: "none"
        })
      }
    },
    //立即购买
    specBuyNow(e) {
      console.log('立即购买--', e)
      //判断选项是否全部选完
      let flag = this.ifSpecListAllChange()
      if (flag) {
        let count = this.data.count;
        let oneselfGroup = this.data.oneselfGroup
        this.closeDialog()
        this.triggerEvent("specBuyNowFunc", {
          count,
          oneselfGroup,
          joinGroupStatus: e.currentTarget.dataset.joingroupstatus ? e.currentTarget.dataset.joingroupstatus : false
        })
      } else {
        wx.showToast({
          title: "请将属性选择完整",
          icon: "none"
        })
      }
    },
    //判断选项是否选完
    ifSpecListAllChange() {
      let specsS = this.data.specsS;
      let length = this.data.specList.length;
      if (specsS.length === length && (specsS.indexOf("") === -1)) {
        return true;
      } else {
        return false
      }
    },

    //向父组件发出事件选择的sku事件
    emitSkuChange() {
      console.log('boxArr', this.data.boxArr);
      let boxArr = this.data.boxArr;
      if (boxArr.stockNum > 0 && boxArr.status == 1) {
        this.triggerEvent('skuObjFun', this.data.boxArr);
      }
    },

    changeCollNum(e) {
      // console.log(e)
      let collInfo = this.data.collInfo
      collInfo[e.detail.collItemkey].showNum = e.detail.showNum;
      console.log(collInfo);
      if (collInfo[e.detail.collItemkey].showNum === 0) {
        collInfo[e.detail.collItemkey].collStatus = false
      } else {
        collInfo[e.detail.collItemkey].collStatus = true
      }
      this.setData({
        collInfo: collInfo
      })
      this.changeCollList()
    },
    changeSelectColl(e) {
      console.log(e, this.data.goodsBargains);
      let collInfo = this.data.collInfo
      if (!collInfo[e.currentTarget.dataset.collindex].collStatus && collInfo[e.currentTarget.dataset.collindex].showNum === 0) {
        collInfo[e.currentTarget.dataset.collindex].showNum = 0;
      } else if (!collInfo[e.currentTarget.dataset.collindex].leastNum) {
        collInfo[e.currentTarget.dataset.collindex].collStatus = !e.currentTarget.dataset.collstatus;
      }
      this.setData({
        collInfo: collInfo
      })
      this.changeCollList()
    }
  },
})